package com.example.demo.controller;

import com.example.demo.service.interf.EmailService;
import com.example.demo.utils.ResultVOUtil;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by hongzhenyue on 18/2/28.
 */
@RestController
//@RequestMapping(value = "/email")
public class EmailController {
    @Autowired
    private EmailService emailService;

    @RequestMapping(value = "/getTestDemoEmail")
    public ResultVO testEmail() {
        String sendTo = "535283049@qq.com";
        String titel = "测试邮件标题";
        String content = "测试邮件内容";
        emailService.sendSimpleMail(sendTo, titel, content);
        return ResultVOUtil.success();
    }

    @RequestMapping(value = "/getTestDemoEmail2")
    public ResultVO testEmail2() {
        String sendTo = "535283049@qq.com";
        String titel = "主题：嵌入静态资源";
        String content = "<html><body>测试html</body></html>";
        List<File> fileList = new ArrayList<>();
        fileList.add(new File("/Users/hongzhenyue/Desktop/backup/spring_boot_demo/src/main/resources/file/logo.png"));
        fileList.add(new File("/Users/hongzhenyue/Desktop/backup/spring_boot_demo/src/main/resources/file/test.pdf"));
        emailService.sendAttachmentsMail(sendTo, titel, content, fileList);
        return ResultVOUtil.success();
    }

    @RequestMapping(value = "/getTestDemoEmail3")
    public ResultVO testEmail3() {
        String sendTo = "535283049@qq.com";
        String titel = "主题：嵌入静态资源";
        String content = "<html><body>测试html</body></html>";

        List<File> fileList = new ArrayList<>();
        fileList.add(new File("/Users/hongzhenyue/Desktop/backup/spring_boot_demo/src/main/resources/file/logo.png"));
        fileList.add(new File("/Users/hongzhenyue/Desktop/backup/spring_boot_demo/src/main/resources/file/test.pdf"));

        emailService.sendTemplateMail(sendTo, titel, content, fileList);
        return ResultVOUtil.success();
    }
}
